package main;

import static org.junit.Assert.*;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import ourfilter.CircularShiftFilter;
import ourfilter.IgnoreWordFilter;
import ourfilter.OurSink;
import ourfilter.SortLinesFilter;
import ourfilter.Source;
import ourfilter.TokenizerFilter;
import pipes.Pipe;
import TransferObjekts.Line;
import TransferObjekts.Word;

public class PushTest {
	static Source src;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		Pipe<Line> p1 = new Pipe<Line>();
		Pipe<Word> p2 = new Pipe<Word>();
		Pipe<Word> p3 = new Pipe<Word>();
		Pipe<Line> p4 = new Pipe<Line>();
		Pipe<Line> p5 = new Pipe<Line>();

		src = new Source("test.txt", p1);

		new TokenizerFilter(p1, p2);
		new IgnoreWordFilter(p2, p3);
		new CircularShiftFilter(p3, p4);
		new SortLinesFilter(p4, p5);
		new OurSink(p5, "out.txt");

	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void test() {
		src.run();
		
		String result[] = new String[4];
		result[0] = "Test case allsources (line 1)";
		result[1] = "allsources Test case (line 1)";
		result[2] = "case allsources Test (line 1)";
		result[3] = null;
		
		BufferedReader br = null;
		try {
			br = new BufferedReader(new FileReader("out.txt"));
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}
		String line = null;
		int i = 0;
		do{
			try {
				line = br.readLine();
				System.out.println(line);
				assertEquals(line, result[i++]);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}while(line != null);
	}

}
